using System;

namespace DotNetNukeMVPWizard.ProjectConfiguration
{
    public abstract class AbstractConfiguration : IConfigurable
    {
        public string Key { get; private set; }

        public virtual string Value { get; set; }

        public string ErrorMessage
        {
            get { return String.Format("The value '{0}' is not valid for placeholder '{1}'.{2}", Value, Key, ErrorReason); }
        }

        private string ErrorReason { get; set; }

        public bool IsOptional { get; private set; }

        public virtual bool IsValid
        {
            get
            {
                bool _IsValid = true;
                if (Value.Equals(string.Empty) && !IsOptional)
                    _IsValid = false;
                return _IsValid;
            }
        }

        public AbstractConfiguration(string key)
            : this(key, String.Empty, false)
        {
        }

        public AbstractConfiguration(string key, string errorReason)
            : this(key, errorReason, false)
        {
        }

        public AbstractConfiguration(string key, string errorReason, bool isOptional)
        {
            if (String.IsNullOrEmpty(key))
                throw new ArgumentNullException("key is null or empty.", "key");
            Key = key;
            ErrorReason = errorReason;
            IsOptional = isOptional;
            Value = "";
        }


    }
}
